package com.company;


import java.math.BigInteger;
import java.util.Scanner;

/**
 * Created by Administrator on 2016.10.26.
 */
public class Main {
    static int m;
    static int n;

    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);

        BigInteger account=new BigInteger("0");

        n=input.nextInt();
        m=input.nextInt();

        for(int i=0;i<n;i++){
            int[] que=new int[m];
            BigInteger[][] map=new BigInteger[m+1][m+1];
            map[0][0]=new BigInteger("0");
            for(int j=0;j<m;j++){
                que[j]=input.nextInt();
            }

            BigInteger number=new BigInteger("2");

            BigInteger max=new BigInteger("0");

            for(int k=0;k<m;k++){
                for(int j=0;j<=k;j++){
                    BigInteger integer1=number.multiply(new BigInteger(""+que[k-j]));
                    BigInteger integer2=number.multiply(new BigInteger(""+que[m-j-1]));
                    integer1=integer1.add(map[k-j][j]);
                    integer2=integer2.add(map[k-j][j]);
                    if(map[k-j+1][j]==null||integer1.compareTo(map[k-j+1][j])>0) {
                        map[k-j+1][j] = integer1;
                    }
                    if(map[k-j][j+1]==null||integer2.compareTo(map[k-j][j+1])>0){
                        map[k-j][j+1]=integer2;
                    }
                }
                number=number.multiply(new BigInteger("2"));
            }

            for(int j=0;j<m;j++){
                if(map[m-j][j].compareTo(max)>0){
                    max=map[m-j][j];
                }
            }

            account=account.add(max);
        }

        System.out.println(account.toString());
    }
}
